package com.wang.模式.创建.单例;

/**
 * @author wang
 * @Description
 * @create 2021-10-12 16:46
 */
public class SingletonTest06 {
    public static void main(String[] args) {
        Singleton6 instance = Singleton6.getInstance();
        Singleton6 instance1 = Singleton6.getInstance();
        System.out.println(instance);
        System.out.println(instance1);
    }
}

class Singleton6{
    private Singleton6() {
    }

    private volatile static Singleton6 instance;

    public static Singleton6 getInstance(){
        if(instance == null){
            synchronized (Singleton6.class){
                if(instance == null){
                    instance = new Singleton6();
                }
            }
        }
        return instance;
    }
}
